//
//  BHSportSignDetailModel.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/8/26.
//

import UIKit

class BHSportSignDetailModel: NSObject {
    var progress: String = "" // 进度
    var targetId: String = ""
    var plan: String = ""  // 计划
    var target: String = "" // 目标（标题）
    var startTime: String = ""
    var endTime: String = ""
    
    var status: Int = 0 //  0:未开始  1:进行中  2:已结束

    var planArray: [BHSportPlanModel] = []
    
    
    fileprivate var progressInt: Int = 0
    
    
    func parseDic(_ dic: [String:Any]) {
        self.progress = BHJsonTool.decodeStringFromDic(dic: dic, key: "progress")
        self.targetId = BHJsonTool.decodeStringFromDic(dic: dic, key: "id")
        self.plan = BHJsonTool.decodeStringFromDic(dic: dic, key: "plan")
        self.target = BHJsonTool.decodeStringFromDic(dic: dic, key: "target")
        self.startTime = BHJsonTool.decodeStringFromDic(dic: dic, key: "startTime")
        self.endTime = BHJsonTool.decodeStringFromDic(dic: dic, key: "endTime")

        self.status = BHJsonTool.decodeIntFromDic(dic: dic, key: "status")
        self.progressInt = BHJsonTool.decodeIntFromDic(dic: dic, key: "progress")
        
        let array = BHJsonTool.decodeArrayFromDic(dic: dic, key: "campaignPlanList")
        if self.planArray.count != 0 {
            self.planArray.removeAll()
        }
        for item in array {
            let model = BHSportPlanModel.init()
            model.parseDic(item as! [String:Any])
            self.planArray.append(model)
        }
        

    }
    
    lazy var progressWidth: CGFloat = {
        if self.progressInt == 0 {
            return 0
        }else {
            let scale = CGFloat(self.progressInt)/100.0
            return 120*scale
        }
    }()
    
    lazy var statusText: String = {
        if self.status == 2 {
            return "已结束"
        }else if self.status == 1 {
            return "进行中"
        }else {
            return "未开始"
        }
    }()
}


class BHSportPlanModel {
    var planId: String = "" // 
    var clockTime: String = ""
    var clockStatus: Int = 0 //  打卡状态 0:待打卡  1:已打卡  2:缺卡
    
    func parseDic(_ dic: [String:Any]) {
        self.clockTime = BHJsonTool.decodeStringFromDic(dic: dic, key: "clockTime")
        self.planId = BHJsonTool.decodeStringFromDic(dic: dic, key: "id")
        self.clockStatus = BHJsonTool.decodeIntFromDic(dic: dic, key: "clockStatus")
     
    }
}
